package com.yykj.hospital.server.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yykj.common.vo.ResultVO;
import com.yykj.hospital.client.dto.HospitalAdminRoleDTO;
import com.yykj.hospital.client.dto.HospitalMenuDTO;
import com.yykj.hospital.client.form.HospitalMenuForm;
import com.yykj.hospital.server.service.HospitalOauthService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/backstage/hospital")
@SuppressWarnings("unchecked")
@Api(tags = "医院菜单权限相关")
public class HospitalOauthController {

    @GetMapping("/menu/list")
    @ApiOperation("获取菜单列表")
    public ResultVO<List<HospitalMenuDTO>> getHospitalMenu(@RequestParam(name = "hospitalId")Integer hospitalId,
                                                           @RequestParam(name = "keyword",required = false) String keyword){
        return ResultVO.success(hospitalOauthService.getHospitalMenu(hospitalId,keyword));
    }


    @PostMapping("/menu/add")
    @ApiOperation("添加菜单")
    @ApiOperationSupport(ignoreParameters = {"id"})
    public ResultVO<HospitalMenuDTO> addHospitalMenu(@RequestBody HospitalMenuForm hospitalMenuForm){
        return ResultVO.success(hospitalOauthService.editHospitalMenu(hospitalMenuForm));
    }

    @PutMapping("/menu/edit")
    @ApiOperation("修改菜单")
    public ResultVO<HospitalMenuDTO> editHospitalMenu(@RequestBody HospitalMenuForm hospitalMenuForm){
        return ResultVO.success(hospitalOauthService.editHospitalMenu(hospitalMenuForm));
    }

    @DeleteMapping("/menu/delete/{id}")
    @ApiOperation("删除菜单")
    public ResultVO deleteHospitalMenu(@PathVariable Integer id){
        hospitalOauthService.deleteHospitalMenu(id);
        return ResultVO.success();
    }

    //=============================================================================================================

    @PostMapping("/role/add")
    @ApiOperation("角色--添加")
    @ApiOperationSupport(ignoreParameters = {"id"})
    public ResultVO<HospitalAdminRoleDTO> addRole(@RequestBody HospitalAdminRoleDTO form){
        return ResultVO.success(hospitalOauthService.editRole(form));
    }

    @PutMapping("/role/edit")
    @ApiOperation("角色--修改")
    public ResultVO<HospitalAdminRoleDTO> editRole(@RequestBody HospitalAdminRoleDTO form){
        return ResultVO.success(hospitalOauthService.editRole(form));
    }

    @DeleteMapping("/role/delete/{id}")
    @ApiOperation("角色--删除")
    public ResultVO<HospitalAdminRoleDTO> deleteRole(@PathVariable Integer id){
        hospitalOauthService.deleteRole(id);
        return ResultVO.success();
    }

    @GetMapping("/role/list")
    @ApiOperation("角色--列表")
    public ResultVO<List<HospitalAdminRoleDTO>> getRoleList(@RequestParam(name = "hospitalId",required = true) Integer hospitalId,
                                                            @RequestParam(name = "adminId",required = false) Integer adminId){
        return ResultVO.success(hospitalOauthService.getHospitalAdminRole(hospitalId,adminId));
    }

    private HospitalOauthService hospitalOauthService;

    @Autowired
    public void setHospitalMenuService(HospitalOauthService hospitalOauthService) {
        this.hospitalOauthService = hospitalOauthService;
    }



}
